/*
   from lidarpacket queue calculate raw pointcloud
*/

#ifndef _PARSER_H_
#define _PARSER_H_
#include "modules/drivers/lidar/orin_hesai/common/data_buffer.h"
#include "modules/drivers/lidar/orin_hesai/common/data_type.h"
#include "modules/drivers/lidar/orin_hesai/common/lidar_gflags.h"
#include "modules/drivers/lidar/orin_hesai/hesai_utils/hesai_parser.h"

namespace apollo {
namespace drivers {
namespace lidar_hesai {

using apollo::drivers::PointCloud;

class LidarParser {
 public:
  bool Init(std::shared_ptr<CircularQueueBuffer<LidarPacket>> packet_buffer,
            std::shared_ptr<CircularQueueBuffer<PointCloud>> pc_buffer);
  LidarParser();
  void Start();

 private:
  void HesaiDataProcess(const LidarPacket* packet);

  void InsertFrame();
  std::shared_ptr<CircularQueueBuffer<LidarPacket>> packet_buffer_;
  // hesai
  HesaiParser hesai_parser_;
  uint32_t frame_first_azimuth_, frame_last_azimuth_;
  uint32_t start_azimuth_, end_azimuth_;
  std::shared_ptr<PointCloud> frame_out_;
  PointCloud* cloud_buf_;
  uint32_t top_lidar_packet_num_;
  uint32_t frame_first_packet_index_;

  std::vector<uint32_t> frame_azimuth_;

  // common
  LidarPacket packet_;
  std::shared_ptr<CircularQueueBuffer<PointCloud>> pc_buffer_;
  uint32_t seq_;
  uint64_t frame_interval_;
  uint32_t drop_count_;
};

}  // namespace lidar_hesai
}  // namespace drivers
}  // namespace apollo
#endif
